<?php
/**
 * Created by PhpStorm.
 * User: s85
 * Date: 2019/6/28
 * Time: 15:40
 */
namespace app\rest\validate;

use think\Validate;

class User extends Validate
{
    // 验证规则
    protected $rule = [
        'name' => ['require', 'min'=>2, 'max'=>20],
        'sex' => ['in'=>'0,1,2'],
        'age' => ['number', 'between'=>'1,120'],
        'tel' => ['require', 'regex'=>'/^1[^012]\d{9}$/'],
        'status' => ['checkStatus']
    ];

    // 提示信息
    protected $message = [
          'name.require' => '你四不四忘了写帐号!!!!!',
          'name.min' => '你输入好短',
          'name.max' => '哇哦~ 你输入好长哦!!'
    ];
    
    // 自定义验证方法
    protected function checkStatus($value)
    {
        if ($value !== 1) {
            return '请选择 [启用] 用户';
        } else {
            return true;
        }
    }



}




